package com.cloud.internalcommon.dto;

import com.cloud.internalcommon.constant.CommonStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class ResponseResult<T> implements Serializable {


    private int code;
    private String message;
    private T data;

    public static <T> ResponseResult<T> instance(){
        return new ResponseResult<>();
    }

    /**
     *
     * @param <T> 数据类型
     * @return ResponseResult实例
     */
    public static <T> ResponseResult<T> success(){
        return new ResponseResult<T>().setCode(CommonStatusEnum.SUCCESS.getCode()).setMessage("操作成功");
    }

    /**
     *
     * @param <T> 数据类型
     * @return ResponseResult实例
     */
    public static <T> ResponseResult<T> success(T code){
        return new ResponseResult<T>().setCode(CommonStatusEnum.SUCCESS.getCode()).setData(code);
    }

    /**
     *
     * @param <T> 数据类型
     * @return ResponseResult实例
     */
    public static <T> ResponseResult<T> fail(){
        return new ResponseResult<T>().setCode(CommonStatusEnum.FAIL.getCode()).setMessage("操作失败");
    }

    /**
     *
     * @param <T> 数据类型
     * @param message 提示信息
     * @return ResponseResult实例
     */
    public static <T> ResponseResult<T> fail(String message){
        return new ResponseResult<T>().setCode(CommonStatusEnum.FAIL.getCode()).setMessage(message);
    }

    /**
     *
     * @param <T> 数据类型
     * @return ResponseResult实例
     */
    public static <T> ResponseResult<T> fail(T code){
        return new ResponseResult<T>().setCode(CommonStatusEnum.FAIL.getCode()).setData(code);
    }
}
